<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/15
 * Time: 9:32
 */
namespace app\home\controller;

use app\home\controller\Base;
use think\Db;

class Renew extends Base {

    protected $model;   // 实例化模型
    /**
     * 初始化
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Renew');
    }

    /**
     * 续费页面
     */
    public function index()
    {
        // 调起扫码的页面地址
        $redirect_url = 'http://'.$_SERVER['HTTP_HOST'].'/home/Renew/index.html';
        // 获取扫码所需参数
        $scan_param = model('Base')->getScanParamB($redirect_url);
        $this->assign('scan_param',$scan_param);
        return view();
    }
    
    /**
     * 验证续费的卡片
     */
    public function checkCard()
    {
        $result = $this->model->checkCardM();
        return $result;
    }

    /**
     * 余额续费页面
     */
    public function renew()
    {
        // 验证卡片信息
        $check = $this->model->checkCardM();
        if($check['code']){
            $this->error();
            exit;
        }
        $this->assign('iccid',$check['card'][0]['iccid']);
        // 根据验证的卡片信息获取卡片的套餐信息
        $card = model('Base')->getCardPackageM($check['card'][0]['pid']);
        if($card['code']){   // 套餐信息错误
            $this->error();
            exit;
        }
        $this->assign('card',$card['package']);
        // 获取账户余额
        $balance = model('Personal')->getMyAccountBalanceM();
        $this->assign('balance',$balance);
        return view();
    }
    
    /**
     * 确定续费
     */
    public function confirmRenew()
    {
        $result = $this->model->confirmRenewM();
        return $result;
    }

}